<template>
	<view>
		<view class="rf-header-box">
			<view class="rf-header">
				<view style="height: 80rpx;line-height: 80rpx;" class="rf-back" @tap="back">
					<text class="iconfont iconzuo"></text>
				</view>
			</view>
		</view>
		
		<uni-swiper-dot :info="zuop.data" :current="current" field="content" :mode="mode">
			<swiper class="swiper-box" @change="change">
				<swiper-item v-for="(item ,index) in zuop.data" :key="index">
					<view class="swiper-item">
						{{item.content}}
						<img width="100%" height="100%" :src="item.url" alt="" srcset="" />
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
		
		<view style="padding: 20rpx 50rpx;">
			<view style="float: right;">
				<img width="20" @click="ispraisetf(zuop.ispraise)" :src="zuop.ispraise==true?'/static/like_start.jpg':'/static/like.jpg'" alt="">
				{{zuop.praise}}
			</view>
			<view style="float: right;">
				<img width="20" src="/static/liul.jpg" alt=""/>
				{{zuop.traffic}}
			</view>
		</view>
		
		<view style="">
			<view style="font-size: 2em;font-weight: bold;">
				作品名称：{{zuop.name}}
			</view>
		</view>
		
		<view style="">
			<view style="">
				文案：{{zuop.introduce}}
			</view>
		</view>
		
		<addImage :zuopinjiId="id" @init="initData(id)"></addImage>
	</view>
</template>

<script>
	import {getOnezpj,goPraise} from "@/api/zpdetail.js"
import addImage from './addimage.vue'
	
	export default {
		components: {addImage},
		data() 
{
			return {
				id:'',//作品集ID
				zuop:{},
				info: [{
					content: '内容 A'
				}, {
					content: '内容 B'
				}, {
					content: '内容 C'
				}],
				current: 0,
				mode: 'round',
			}
		},
		onLoad(options){
			this.id=options.id;
			this.initData(this.id);
			console.log(options);
			console.log(this.id);
		},
		onShow() {
			// this.initData(this.id);
		},
		methods: {
			async ispraisetf(ispraise){
				var dates = new Date().getTime()/1000;
				dates = parseInt(dates);
				var datb={
					"creationId":this.zuop.id,//作品id
				    "username":"zhangsan",//点赞者
				    "praise_time":dates//点赞时间
				};
				
				goPraise(datb).then(res=>{
					console.log(res.data);
					if(res.data.msg=="点赞成功"){
						this.zuop.ispraise=true;
						var a = parseInt(this.zuop.praise);
						a=a+1;
						this.zuop.praise=a+"";
					}else{
						this.zuop.ispraise=false;
						var a = parseInt(this.zuop.praise);
						a=a-1;
						this.zuop.praise=a+"";
					}
				});
			},
			// 数据初始化
			async initData(idd) {
				var data={
					"idd":idd,
					"author":"zhangsan"
				}
				const res = await getOnezpj(data);
				this.zuop=res.data.data;
				
				// uni.request({
				// 	url:"http://1.92.82.82:3001/api/Creation/one/"+idd+"?username=zhangsan",
				// 	method: 'get',
				// 	success: (res) => {
				// 		// console.log(res.data);
				// 		this.zuop=res.data.data;
				// 		console.log(res.data.data);
				// 		// console.log(this.zuop.data[0].url);
				// 	},
				// 	fail: (err) => {
				// 		console.log('请求失败：', err);
				// 	},
				// 	complete: () => {
				// 		console.log('请求完成');
				// 	}
				// })
			},
			change(e) {
				this.current = e.detail.current;
			},
			back() {
				if (this.drawer) {
					this.closeDrawer()
				} else {
					this.$mRouter.back();
				}
			}
		}
	}
</script>

<style>
.swiper-box {
		height: 700rpx;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 700rpx;
		color: #fff;
	}

	
</style>
